﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using TraceThisItem.Domain;

namespace TraceThisItem.WebUI.Account
{
	public partial class Register : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			//RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
		}

		protected void RegisterUser_CreatedUser(object sender, EventArgs e)
		{
			var mUser = Membership.GetUser(RegisterUser.UserName);
			var user = new Domain.User
			{
				UserName = mUser.UserName,
				Firstname = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Firstname")).Text,
				Lastname = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Lastname")).Text
			};

			Facade.Instance.AddUser(user);

			//FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);

			/*
			string continueUrl = RegisterUser.ContinueDestinationPageUrl;
			if (String.IsNullOrEmpty(continueUrl))
			{
				continueUrl = "~/";
			}
			Response.Redirect(continueUrl);
			 */

			Response.Redirect("~/Account/Default.aspx");
		}

	}
}
